﻿using MES_SystemUI.UI.DataDictUI.Stores;
using MES_SystemUI.UI.DataDictUI.ProductsDataDic;
using MES_SystemUI.UI.GlobalSet;
using MES_SystemUI.UI.DataDictUI.User;
using MES_SystemUI.UI.DataDictUI.WorkShops;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MES_SystemUI.UI
{
    public partial class MainForm : Form
    {
        // 系统 公共数据存放 类
        public static SystemDataConfig SystemDataConfig = new SystemDataConfig();
        #region 窗体控制字段


        Point mouseOff;//鼠标移动位置变量
        bool leftFlag;//标签是否为左键
        bool isLeftTop = false;  // 左上边框拖动改变大小，需要改变窗体左上角位置坐标
        bool isMouseDown = false; //表示鼠标当前是否处于按下状态，初始值为否 
        int dis = 4;
        MouseDirection direction = MouseDirection.None;//表示拖动的方向，起始为None，表示不拖动
        #endregion

        #region 业务逻辑窗口实例

        Home home = new Home();
        ProductsPutin productsPutin = new ProductsPutin();
        StoresPutin storesPutin = new StoresPutin();
        TeamsPutin teamsPutin = new TeamsPutin();
        ProductionLinesPutin productionLinesPutin = new ProductionLinesPutin();
        WorkShopsPutin workShopsPutin = new WorkShopsPutin();
        DevicesPutin devicesPutin = new DevicesPutin();
        DeviceMaintenancesPutin deviceMaintenancesPutin = new DeviceMaintenancesPutin();
        DeviceInspectionsPutin deviceInspectionsPutin = new DeviceInspectionsPutin();
        ProductionProcessesPutin productionProcessesPutin = new ProductionProcessesPutin();
        ProductionTechnologiesPutin productionTechnologiesPutin = new ProductionTechnologiesPutin();
        ProductionTechnologiesUpdataPutin productionTechnologiesUpdataPutin = new ProductionTechnologiesUpdataPutin();
        ProductionPlanPutin productionPlanPutin = new ProductionPlanPutin();
        ProductionSchedulingData productionSchedulingData = new ProductionSchedulingData();
        GetMaterialsPutin getMaterialsPutin = new GetMaterialsPutin();
        ProductionReportPutin productionReportPutin = new ProductionReportPutin();
        ReturnOfMaterialPutin returnOfMaterialPutin = new ReturnOfMaterialPutin();
        ReworkPutin reworkPutin = new ReworkPutin();
        ProductionRecoveryData productionRecoveryData = new ProductionRecoveryData();
        GlobalSet.GlobalSet globalSet = new GlobalSet.GlobalSet();
        #endregion

        // 数据字典
        ProductsDataDicForm productsDataDicForm = new ProductsDataDicForm();
        UserDataDicForm userDataDicForm = new UserDataDicForm();
        ProductsListForm productsListForm = new ProductsListForm();
        UnitsListForm unitsListForm = new UnitsListForm();
        ProductSpecsListForm productSpecsListForm = new ProductSpecsListForm();
        WorkShopCategoriesListForm workShopCategoriesListForm = new WorkShopCategoriesListForm();
        WorkShopsDataDicForm workShopsDataDicForm = new WorkShopsDataDicForm();
        TeamMembersListForm TeamMembersListForm = new TeamMembersListForm();
        ProductionLinesListForm ProductionLinesListForm = new ProductionLinesListForm();
        StoreCategoriesListForm storeCategoriesListForm = new StoreCategoriesListForm();
        StoresListForm storesListForm = new StoresListForm();
        TeamsListForm teamsListForm = new TeamsListForm();
        ProductionLineCategoriesListForm productionLineCategoriesListForm = new ProductionLineCategoriesListForm();
        DeviceSpecsListForm deviceSpecsListForm = new DeviceSpecsListForm();
        DeviceCategoriesListForm deviceCategoriesListForm = new DeviceCategoriesListForm();
        ProductionTechnologiesListForm productionTechnologiesListForm = new ProductionTechnologiesListForm();
        ProductionTechnologyDetailsListForm productionTechnologyDetailsListForm = new ProductionTechnologyDetailsListForm();
        ProductionProcesseListForm productionProcesseListForm = new ProductionProcesseListForm();
        public MainForm()
        {
            InitializeComponent();
            #region 业务逻辑窗口

            首页ToolStripMenuItem.Click += 首页ToolStripMenuItem_Click;
            产品信息ToolStripMenuItem.Click += 产品信息ToolStripMenuItem_Click;
            仓库信息ToolStripMenuItem.Click += 仓库信息ToolStripMenuItem_Click;
            班组信息ToolStripMenuItem.Click += 班组信息ToolStripMenuItem_Click;
            产线信息ToolStripMenuItem.Click += 产线信息ToolStripMenuItem_Click;
            车间信息ToolStripMenuItem.Click += 车间信息ToolStripMenuItem_Click;
            工序信息ToolStripMenuItem.Click += 工序信息ToolStripMenuItem_Click;
            工艺线路ToolStripMenuItem.Click += 工艺线路ToolStripMenuItem_Click;
            工艺更新ToolStripMenuItem.Click += 工艺更新ToolStripMenuItem_Click;
            生产计划ToolStripMenuItem.Click += 生产计划ToolStripMenuItem_Click;
            生产排产ToolStripMenuItem.Click += 生产排产ToolStripMenuItem_Click;
            生产领料ToolStripMenuItem.Click += 生产领料ToolStripMenuItem_Click;
            生产报工ToolStripMenuItem.Click += 生产报工ToolStripMenuItem_Click;
            生产退料ToolStripMenuItem.Click += 生产退料ToolStripMenuItem_Click;
            返工生产ToolStripMenuItem.Click += 返工生产ToolStripMenuItem_Click;
            生产恢复ToolStripMenuItem.Click += 生产恢复ToolStripMenuItem_Click;
            进度指标看板ToolStripMenuItem.Click += 进度指标看板ToolStripMenuItem_Click;
            报工量化表ToolStripMenuItem.Click += 报工量化表ToolStripMenuItem_Click;
            原料领取记录ToolStripMenuItem.Click += 原料领取记录ToolStripMenuItem_Click;
            退料数据看板ToolStripMenuItem.Click += 退料数据看板ToolStripMenuItem_Click;
            返工数据分析ToolStripMenuItem.Click += 返工数据分析ToolStripMenuItem_Click;
            原料库存ToolStripMenuItem.Click += 原料库存ToolStripMenuItem_Click;
            成品仓库ToolStripMenuItem.Click += 成品仓库ToolStripMenuItem_Click;
            待检清单ToolStripMenuItem.Click += 待检清单ToolStripMenuItem_Click;
            返工清单ToolStripMenuItem.Click += 返工清单ToolStripMenuItem_Click;
            报废清单ToolStripMenuItem.Click += 报废清单ToolStripMenuItem_Click;
            设备登记ToolStripMenuItem.Click += 设备登记ToolStripMenuItem_Click;
            设备检修ToolStripMenuItem.Click += 设备检修ToolStripMenuItem_Click;
            巡检记录ToolStripMenuItem.Click += 巡检记录ToolStripMenuItem_Click;
            设置ToolStripMenuItem.Click += 设置ToolStripMenuItem_Click;
            #endregion

            // 数据字典
            产品类型ToolStripMenuItem.Click += 产品类型ToolStripMenuItem_Click;
            用户信息ToolStripMenuItem.Click += 用户信息ToolStripMenuItem_Click;
            产品信息ToolStripMenuItem1.Click += 产品信息ToolStripMenuItem1_Click;
            单位信息ToolStripMenuItem.Click += 单位信息ToolStripMenuItem_Click;
            产品规格ToolStripMenuItem.Click += 产品规格ToolStripMenuItem_Click;
            车间信息ToolStripMenuItem1.Click += 车间信息ToolStripMenuItem1_Click;
            车间类型ToolStripMenuItem.Click += 车间类型ToolStripMenuItem_Click;
            班组信息ToolStripMenuItem1.Click += 班组信息ToolStripMenuItem1_Click;
            产线信息ToolStripMenuItem1.Click += 产线信息ToolStripMenuItem1_Click;
            仓库类型ToolStripMenuItem.Click += 仓库类型ToolStripMenuItem_Click;
            仓库信息ToolStripMenuItem1.Click += 仓库信息ToolStripMenuItem1_Click;
            班组成员ToolStripMenuItem.Click += 班组成员ToolStripMenuItem_Click;
            产线类型ToolStripMenuItem.Click += 产线类型ToolStripMenuItem_Click;
            设备规格ToolStripMenuItem.Click += 设备规格ToolStripMenuItem_Click;
            设备类型ToolStripMenuItem.Click += 设备类型ToolStripMenuItem_Click;
            工艺信息ToolStripMenuItem.Click += 工艺信息ToolStripMenuItem_Click;
            工艺工序ToolStripMenuItem.Click += 工艺工序ToolStripMenuItem_Click;
            工序信息ToolStripMenuItem1.Click += 工序信息ToolStripMenuItem1_Click;

            this.BackColor = SystemDataConfig.MainFormTitleBackColor;
            panel1.BackColor = SystemDataConfig.MainFormTitleBackColor;
            button1.ForeColor = SystemDataConfig.MainFormTitleFontcolor;
            button2.ForeColor = SystemDataConfig.MainFormTitleFontcolor;
            button3.ForeColor = SystemDataConfig.MainFormTitleFontcolor;
            button4.ForeColor = SystemDataConfig.MainFormTitleFontcolor;
            #region 窗体移动控制

            this.MouseMove += MainForm_MouseMove;
            this.MouseDown += MainForm_MouseDown;
            this.MouseUp += MainForm_MouseUp;
            panel1.MouseDown += Panel1_MouseDown;
            panel1.MouseUp += Panel1_MouseUp;
            panel1.MouseMove += Panel1_MouseMove;
            panel2.MouseMove += Panel2_MouseMove;
            panel3.MouseMove += Panel3_MouseMove;
            button1.Click += Button1_Click;
            button2.Click += Button2_Click;
            button3.Click += Button3_Click;
            button4.Click += Button4_Click;
            this.Load += MainForm_Load;
            this.Resize += MainForm_Resize;
            panel2.Padding = new Padding(8);
            #endregion

        }

        private void 工序信息ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            OpenForm(productionProcesseListForm);
        }

        private void 工艺工序ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenForm(productionTechnologyDetailsListForm);
        }

        private void 工艺信息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenForm(productionTechnologiesListForm);
        }

        private void 设备类型ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenForm(deviceCategoriesListForm);
        }

        private void 设备规格ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenForm(deviceSpecsListForm);
        }

        private void 产线类型ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenForm(productionLineCategoriesListForm);
        }

        private void 班组成员ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenForm(TeamMembersListForm);
        }

        private void 仓库信息ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            OpenForm(storesListForm);
        }

        private void 仓库类型ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenForm(storeCategoriesListForm);
        }

        private void 产线信息ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            OpenForm(ProductionLinesListForm);
        }

        private void 班组信息ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            OpenForm(teamsListForm);
        }

        private void 车间类型ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenForm(workShopCategoriesListForm);
        }

        private void 车间信息ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            OpenForm(workShopsDataDicForm);
        }

        private void 产品规格ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenForm(productSpecsListForm);
        }

        private void 单位信息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenForm(unitsListForm);
        }

        private void 产品信息ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            OpenForm(productsListForm);
        }

        private void 用户信息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenForm(userDataDicForm);
        }

        #region 业务逻辑界面控制

        private void 设置ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenForm(globalSet);
        }

        private void 产品类型ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenForm(productsDataDicForm);
        }

        private void 巡检记录ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenForm(deviceInspectionsPutin);
        }

        private void 设备检修ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenForm(deviceMaintenancesPutin);
        }

        private void 设备登记ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenForm(devicesPutin);
        }

        private void 报废清单ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenForm(productsPutin);
        }

        private void 返工清单ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenForm(productsPutin);
        }

        private void 待检清单ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenForm(productsPutin);
        }

        private void 成品仓库ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenForm(productsPutin);
        }

        private void 原料库存ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenForm(productsPutin);
        }

        private void 返工数据分析ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenForm(productsPutin);
        }

        private void 退料数据看板ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenForm(productsPutin);
        }

        private void 原料领取记录ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenForm(productsPutin);
        }

        private void 报工量化表ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenForm(productsPutin);
        }

        private void 进度指标看板ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenForm(productsPutin);
        }

        private void 生产恢复ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenForm(productionRecoveryData);
        }

        private void 返工生产ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenForm(reworkPutin);
        }

        private void 生产退料ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenForm(returnOfMaterialPutin);
        }

        private void 生产报工ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenForm(productionReportPutin);
        }

        private void 生产领料ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenForm(getMaterialsPutin);
        }

        private void 生产排产ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenForm(productionSchedulingData);
        }

        private void 生产计划ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenForm(productionPlanPutin);
        }

        private void 工艺更新ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenForm(productionTechnologiesUpdataPutin);
        }

        private void 工艺线路ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenForm(productionTechnologiesPutin);
        }

        private void 工序信息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenForm(productionProcessesPutin);
        }

        private void 车间信息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenForm(workShopsPutin);
        }

        private void 产线信息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenForm(productionLinesPutin);
        }

        private void 班组信息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenForm(teamsPutin);
        }

        private void 仓库信息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenForm(storesPutin);
        }

        private void 产品信息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenForm(productsPutin);
        }
        private void 首页ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenForm(home);
        }

        private void OpenForm(Form fron)
        {
            panel2.Controls.Clear();
            fron.TopLevel = false;
            panel2.Controls.Add(fron);
            fron.Dock = DockStyle.Fill;
            fron.Show();
        }
        #endregion

        #region 窗体控制

        private void Panel3_MouseMove(object sender, MouseEventArgs e)
        {
            this.Cursor = Cursors.Arrow;
        }

        private void MainForm_Resize(object sender, EventArgs e)
        {
            if (panel2.Controls.Count == 1)
            {
                Control control = panel2.Controls[0];
                control.Dock = DockStyle.Fill;
            }
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            OpenForm(home);
        }

        #region 窗体基本功能

        // 关闭
        private void Button4_Click(object sender, EventArgs e)
        {
            this.Close();

            Environment.Exit(0);
        }
        // 最大化
        private void Button3_Click(object sender, EventArgs e)
        {
            if (this.WindowState == FormWindowState.Maximized)
            {
                WindowState = FormWindowState.Normal;
            }
            else
            {
                WindowState = FormWindowState.Maximized;
            }
        }
        // 最小化
        private void Button2_Click(object sender, EventArgs e)
        {
            WindowState |= FormWindowState.Minimized;
        }
        // 置顶
        private void Button1_Click(object sender, EventArgs e)
        {
            this.TopMost = !this.TopMost;
            if (this.TopMost)
            {
                button1.ForeColor = SystemDataConfig.MainFormTopMostColor;
            }
            else
            {
                button1.ForeColor = Color.Black;
            }
        }
        #endregion

        private void Panel2_MouseMove(object sender, MouseEventArgs e)
        {
            this.Cursor = Cursors.Arrow;
        }
        #region 无边框窗体拖动

        private void Panel1_MouseMove(object sender, MouseEventArgs e)
        {
            this.Cursor = Cursors.Arrow;
            if (leftFlag)
            {
                Point mouseSet = Control.MousePosition;
                mouseSet.Offset(mouseOff.X, mouseOff.Y);  //设置移动后的位置
                Location = mouseSet;
            }
        }

        //添加窗体的MouseDown事件，并编写如下代码
        private void Panel1_MouseDown(object sender, MouseEventArgs e)
        {
            isMouseDown = true;
            if (e.Button == MouseButtons.Left)
            {
                mouseOff = new Point(-e.X, -e.Y); //得到变量的值
                leftFlag = true;                  //点击左键按下时标注为true;
            }
        }
        private void Panel1_MouseUp(object sender, MouseEventArgs e)
        {
            isMouseDown = false;
            direction = MouseDirection.None;
            if (leftFlag)
            {
                leftFlag = false;//释放鼠标后标注为false;
            }
        }

        #endregion
        #region 无边框窗体大小

        private void MainForm_MouseUp(object sender, MouseEventArgs e)
        {
            isMouseDown = false;
            direction = MouseDirection.None;
            if (leftFlag)
            {
                leftFlag = false;//释放鼠标后标注为false;
            }
        }

        private void MainForm_MouseDown(object sender, MouseEventArgs e)
        {
            isMouseDown = true;
            if (e.Button == MouseButtons.Left)
            {
                mouseOff = new Point(-e.X, -e.Y); //得到变量的值
                leftFlag = true;                  //点击左键按下时标注为true;
            }
        }
        private void MainForm_MouseMove(object sender, MouseEventArgs e)
        {
            //如果鼠标按下，同时有方向箭头那么直接调整大小,这里是改进的地方，不然斜角拉的过程中，会有问题
            if (isMouseDown && direction != MouseDirection.None)
            {
                //设定好方向后，调用下面方法，改变窗体大小  
                ResizeWindow();
                return;
            }
            //鼠标移动过程中，坐标时刻在改变 
            //当鼠标移动时横坐标距离窗体右边缘5像素以内
            //且纵坐标距离下边缘也在5像素以内时
            //要将光标变为倾斜的箭头形状
            //同时拖拽方向direction置为MouseDirection.Declining 
            if (e.Location.X >= this.Width - dis && e.Location.Y >= this.Height - dis)
            {
                this.Cursor = Cursors.SizeNWSE;
                isLeftTop = false;
                direction = MouseDirection.Declining;
            }
            // 同理 左上角
            else if (e.Location.X <= dis && e.Location.Y <= dis)
            {
                this.Cursor = Cursors.SizeNWSE;
                isLeftTop = true;
                direction = MouseDirection.Declining;
            }
            //当鼠标移动时横坐标距离窗体右边缘5像素以内时，要将光标变为倾斜的箭头形状，同时拖拽方向direction置为MouseDirection.Herizontal
            else if (e.Location.X >= this.Width - dis)
            {
                this.Cursor = Cursors.SizeWE;
                isLeftTop = false;
                direction = MouseDirection.Herizontal;
            }
            // 同理，左
            else if (e.Location.X <= dis)
            {
                this.Cursor = Cursors.SizeWE;
                isLeftTop = true;
                direction = MouseDirection.Herizontal;
            }

            //同理当鼠标移动时纵坐标距离窗体下边缘5像素以内时，要将光标变为倾斜的箭头形状，同时拖拽方向direction置为MouseDirection.Vertical
            else if (e.Location.Y >= this.Height - dis)
            {
                this.Cursor = Cursors.SizeNS;
                isLeftTop = false;
                direction = MouseDirection.Vertical;
            }
            // 同理 上
            else if (e.Location.Y <= dis)
            {
                this.Cursor = Cursors.SizeNS;
                isLeftTop = true;
                direction = MouseDirection.Vertical;
            }
            //否则，以外的窗体区域，鼠标星座均为单向箭头（默认）    按下时可移动界面  
            //else if (e.Location.X >dis&&e.Location.X<= this.Width - dis && e.Location.Y>dis&&e.Location.Y<=this.Height-dis)
            //{
            //    this.Cursor = Cursors.Arrow;
            //}
            else
            {
                isLeftTop = false;
                this.Cursor = Cursors.Arrow;
                //if (leftFlag)
                //{
                //    Point mouseSet = Control.MousePosition;
                //    mouseSet.Offset(mouseOff.X, mouseOff.Y);  //设置移动后的位置
                //    Location = mouseSet;
                //}
            }
        }

        private void ResizeWindow()
        {
            //这个判断很重要，只有在鼠标按下时才能拖拽改变窗体大小，如果不作判断，那么鼠标弹起和按下时，窗体都可以改变 
            if (!isMouseDown)
                return;
            //MousePosition的参考点是屏幕的左上角，表示鼠标当前相对于屏幕左上角的坐标this.left和this.top的参考点也是屏幕，属性MousePosition是该程序的重点
            if (direction == MouseDirection.Declining && !isLeftTop)
            {
                //此行代码在mousemove事件中已经写过，在此再写一遍，并不多余，一定要写
                this.Cursor = Cursors.SizeNWSE;
                //下面是改变窗体宽和高的代码，不明白的可以仔细思考一下
                this.Width = MousePosition.X - this.Left;
                this.Height = MousePosition.Y - this.Top;
            }
            else if (direction == MouseDirection.Declining && isLeftTop)
            {
                this.Cursor = Cursors.SizeNWSE;
                this.Width = this.Width + this.Left - MousePosition.X;
                this.Left = MousePosition.X;
                this.Height = this.Height + this.Top - MousePosition.Y;
                this.Top = MousePosition.Y;
            }
            //以下同理
            if (direction == MouseDirection.Herizontal && !isLeftTop)
            {
                this.Cursor = Cursors.SizeWE;
                this.Width = MousePosition.X - this.Left;
            }
            else if (direction == MouseDirection.Herizontal && isLeftTop)
            {
                this.Cursor = Cursors.SizeWE;
                this.Width = this.Width + this.Left - MousePosition.X;
                this.Left = MousePosition.X;

            }
            else if (direction == MouseDirection.Vertical && !isLeftTop)
            {
                this.Cursor = Cursors.SizeNS;
                this.Height = MousePosition.Y - this.Top;
            }
            else if (direction == MouseDirection.Vertical && isLeftTop)
            {
                this.Cursor = Cursors.SizeNS;
                this.Height = this.Height + this.Top - MousePosition.Y;
                this.Top = MousePosition.Y;
            }
            //即使鼠标按下，但是不在窗口右和下边缘，那么也不能改变窗口大小
            else
                this.Cursor = Cursors.Arrow;
        }
        #endregion
    }

    public enum MouseDirection
    {
        Herizontal,//水平方向拖动，只改变窗体的宽度
        Vertical,//垂直方向拖动，只改变窗体的高度
        Declining,//倾斜方向，同时改变窗体的宽度和高度
        None//不做标志，即不拖动窗体改变大小
    }
    #endregion

}
